package cn.wizzer.modules.controllers.platform.customer;

import cn.wizzer.common.annotation.SLog;
import cn.wizzer.common.base.Result;
import cn.wizzer.common.filter.PrivateFilter;
import cn.wizzer.common.page.DataTableColumn;
import cn.wizzer.common.page.DataTableOrder;
import cn.wizzer.modules.models.customer.Customer;
import cn.wizzer.modules.models.sys.Sys_user;
import cn.wizzer.modules.services.customer.CustomerService;
import cn.wizzer.modules.services.sys.SysUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.subject.Subject;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

@IocBean
@At("/platform/customer/end")
@Filters({@By(type = PrivateFilter.class)})
public class CustomerEndController {
	private static final Log log = Logs.get();
	@Inject
	private CustomerService customerService;
	@Inject
	private SysUserService sysUserService;


	@At("")
	@Ok("beetl:/platform/customer/customer/endIndex.html")
	@RequiresAuthentication
	public void index() {

	}

	@At
	@Ok("json:full")
	@RequiresAuthentication
	public Object data(@Param("length") int length, @Param("start") int start, @Param("draw") int draw, @Param("::order") List<DataTableOrder> order, @Param("::columns") List<DataTableColumn> columns,@Param("..") Customer customer) {
		Cnd cnd = Cnd.NEW();
		if(!Strings.isBlank(customer.getCompanyName())){
			cnd.and("companyName","like","%"+customer.getCompanyName()+"%");
		}
		if(!Strings.isBlank(customer.getContactsName())){
			cnd.and("contactsName","like","%"+customer.getContactsName()+"%");
		}
		cnd.and("state","=",customer.getState());
		return customerService.data(length, start, draw, order, columns, cnd, null);
	}



	
}
